int main()
{
//通過IP端口創建協議
auto protocol = techlego::create_binary_protocol(L"localhost", 5252);
//通過協議創建客戶端
auto client = techlego::h_scan3d_client::make_shared(protocol);
//坐標系1下的點坐標
std::array<techlego::pos3f, 4>points1 = {
{ {-65.4562 ,-54.4644,378.7092},
{-65.3003 ,-54.4709 ,378.7567},
{-15.7148 ,-14.9020,380.3256 },
{-65.2903 ,- 54.4111 ,378.7333} } };
//坐標系2下的點坐標
std::array<techlego::pos3f, 4>points2 = {};
// 構建繞Z軸旋轉45度的旋轉矩陣
Eigen::AngleAxisd angle_axis(M_PI / 4, Eigen::Vector3d(0, 0, 1));
Eigen::Matrix3d m = angle_axis.toRotationMatrix();
// 構建平移向量
Eigen::Vector3d translate_vector(1, 3, 4);
// 對坐標系1中的點應用之前構建的旋轉矩陣和平移向量,得到坐標系2下的該點
for (int i = 0; i < points1.size(); i++)
{
// 用變換矩陣對坐標進行變換
// 點在坐標系1下坐標
Eigen::Vector3d point(points1[i].m_x, points1[i].m_y, points1[i].m_z);
// 變換,相當于【旋轉矩陣*坐標+平移向量】
Eigen::Vector3d point_after_trans = m * point + translate_vector;
std::cout << "變換后的坐標為:" << std::endl << point_after_trans.transpose() << std::endl;
points2[i].m_x = point_after_trans(0);
points2[i].m_y = point_after_trans(1);
points2[i].m_z = point_after_trans(2);
}
//輸入,配對點的數量
int total = static_cast<int>(points1.size());
//輸出,旋轉矩陣
//輸出,平移向量
double mm[3][3] = { 0 }, t[3] = { 0 };
//由點對獲取坐標系1變換到坐標系2下的旋轉矩陣和平移向量
auto pairs = techlego::am::get_rt_by_pt_pairs(points2.data(), points1.data(), total, mm, t);
std::cout << "原旋轉矩陣:\n" << m << "\n";
std::cout << "原平移向量:" << translate_vector.transpose() << "\n";
std::cout << "解得的旋轉矩陣:";
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
std::cout << " " << mm[i][j] << '\t';
}
std::cout << std::endl;
}
std::cout << "解得的平移向量:";
for (int i = 0; i < 3; i++)
{
std::cout << t[i] << " ";
}
std::cout << "\n各個點對距離的平方和:" << pairs << std::endl;
return 0;
}